package com.clss.emergencycall.popAndDialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.Window
import android.widget.Button
import android.widget.EditText
import com.clss.emergencycall.R

class EditDialog(context: Context, callback : EditDialogCallback) :
        Dialog(context) {

    lateinit var mEt : EditText
    lateinit var mOkBtn : Button
    lateinit var mNoBtn : Button
    var mShowEt : Boolean
    var mCallback: EditDialogCallback

    init {
        mCallback = callback
        mShowEt = true
    }

    constructor(context: Context, showEt : Boolean, callback : EditDialogCallback):
    this(context, callback){
        mCallback = callback
        mShowEt = showEt
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.dialog_edit)
        window?.setBackgroundDrawableResource(android.R.color.transparent)
        mEt = findViewById(R.id.tv_dialog_et)
        mOkBtn = findViewById(R.id.btn_dialog_ok)
        mNoBtn = findViewById(R.id.btn_dialog_no)
        if (!mShowEt){
            mEt.visibility = View.GONE
        }
        mOkBtn.setOnClickListener {
            mCallback.clickOkListener(mEt.text.toString())
            dismiss()
        }
        mNoBtn.setOnClickListener {
            dismiss()
        }
    }

    interface EditDialogCallback{
        fun clickOkListener(contant : String)
    }
}

